//MiniOS Version 1.0
//Created By: Joshua Nixon
//Greets: Raemar(Coding Concepts), Blake Royer(Snake Game)
#include <iostream.h>
#include <graphics.h>
#include <fstream.h>
#include <dos.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <time.h>
class MiniOS
{
 private:
 //This will hold the attribute for the window
 struct WndAttribute
  {
   int WndSize;//Size of the window in memory
   int WndX1;//The X1 coordinate(Top Right)
   int WndY1;//The Y1 coordinate(Top Right)
   int WndX2;//The X2 coordinate(Bottom Left)
   int WndY2;//The Y2 coordinate(Bottom Left)
   int WndStyle;//How window will appear to user
   int WndFcColor;//Window on Focus Color
   int WndLFcColor;//Window on Lost Focus Color
   int WndBackGrd;//Color of the windows background
   //Icons Later add..
   int WndTitleLine;//The color of the lines on the title bar
  };

 //We need the exact same kind of struct to hold the coordinates and info in mem
 struct BackBuff
  {
   int WndSize;//Size of the window in memory
   int WndX1;//The X1 coordinate(Top Right)
   int WndY1;//The Y1 coordinate(Top Right)
   int WndX2;//The X2 coordinate(Bottom Left)
   int WndY2;//The Y2 coordinate(Bottom Left)
   int WndStyle;//How window will appear to user
   int WndFcColor;//Window on Focus Color
   int WndLFcColor;//Window on Lost Focus Color
   int WndBackGrd;//Color of the windows background
   //Icons Later add..
   int WndTitleLine;//The color of the lines on the title bar
  };


 //This will hold the quality (esstentail quality)
 struct WndQuality
  {
   char* WndName;//The window name in memory will work like a handle;
   char* WndCaption;//The windows Title Bar Caption
  };

 //Create the folder for the window
 struct WndFolder
  {
   int X;
   int Y;
   int Color;
  };
 struct WndFile
  {
   char* FileName;
   char* Bytes;
  };

 //Use inheritance to grab the member for the each Structure
 struct WndMain
  {
   WndAttribute WndAttr;
   WndQuality WndQual;
   WndFolder WndFol;
  };
 struct UserInfo
  {
   char *ID;//This will hold the User Name
   char *CODE;//This will hold the Password
  };

 //This struct will hold the data for the new user
 struct Wizard_Info
  {
   char Id[15];
   char Code[15];
   char First[15];
   char Last[15];
   char Sex[15];
  };

 //*******************************************************************
 //End Structure Declarations
 //*******************************************************************
 char* Emotion[4];
 char* TitleBarButtons[2];//Used for close button, minimize button, max button
 char* ButtonLabel[3];
 char* InputBoxSy;//Icon for the inputbox
 char* LogFileName;//The Filename for the log file to save\load .
 char Time[15];
 char Date[15];



 int Mouse_x;//Used to hold the X coordinate of the cursor
 int Mouse_y;//Used to hold the Y coordinate of the cursor
 int WndCount;


 public:
  void Create_Log_File();
  void Drawsprite(char SpriteFile[12],int XCo, int YCo, int StartX,
			int StartY);

  int CreateWindow(int WndX1,int WndY1,int WndX2,int WndY2,
		   int WndStyle, int WndFcColor, int WndLFcColor,
		   int WndBackGrd, int WndTitleLine);

  int TypeEngine(int XCor, int YCor,int Visible_Color, int Cover_Color,
		 int XBound, int YBound, int BackSpace_Bound, int Tab_Bound,
		 int Return_TabCoor);
  void GetMousePos(int *button,int *x, int *y);//Get the mouse position
  void Hide_Cursor();
  int CreateFolder(int X, int Y, int Color);
  void CreateTxtBox_Lbl(int X1, int Y1, int X2, int Y2,char* TxtLabel);
  void CreateMsgBox(int MsgStyle, int ChoiceEm,char* Line1, char* Line2,
			  char* Line3, char* Line4, char* Line5);
  void User_Wizard();
  void Get_Wnd_Visual();
  //Function for making the mouse work
  void GetClick(int bta,int btb,int link[][5]);
  void Mouse_Enable();
  void Mouse_Read_Cursor();
  void ShowMouse();
  //Set default values for struct window
  void Set_Default();
  void Create_Entire_Interface();
  void Set_WndNumber();
  union REGS i,o;//
  BackBuff BkBuff[100];//Hold the grpahics back buffer data

  //*******************************************************
  //Set all the values for the variables used throughout
  //the class [default construtor]
  //*******************************************************
  MiniOS::MiniOS()
   {
    WndCount = 0;
    //Hold the coordinates and detail of windows
    TitleBarButtons[0] = new char[1];
    TitleBarButtons[1] = new char[1];
    TitleBarButtons[2] = new char[1];
    Emotion[0] = new char[1];
    Emotion[1] = new char[1];
    Emotion[2] = new char[1];
    Emotion[3] = new char[1];
    InputBoxSy = new char[1];
    ButtonLabel[0] = new char[3];
    ButtonLabel[1] = new char[7];
    ButtonLabel[2] = new char[4];
    ButtonLabel[3] = new char[3];
    LogFileName = new char[255];

    _strtime(Time);//Convert to string
    _strdate(Date);//Convert to string
    strcat(Date,Time);//Do a nice little trick to store both of them in one

    //*****************************************
    //Allocation errors
    if((!TitleBarButtons[0]) || (!TitleBarButtons[1]) || (!TitleBarButtons[2]) ||
       (!Emotion[0]) || (!Emotion[1]) || (!Emotion[2]) || (!Emotion[3]) ||
       (!InputBoxSy) || (!LogFileName) )

	cout<<"Error allocating memory for window";


    //This is for the message box
    strcpy(Emotion[0],"?");//Question(Do what now)
    strcpy(Emotion[1],"!");//Explanation(Listen Up)
    strcpy(Emotion[2],"X");//Critical(UH Oh)
    strcpy(Emotion[3],"I");//Default

    //This is the titlebar button used on the very right to close open minimize
    strcpy(TitleBarButtons[0],"X");
    strcpy(TitleBarButtons[1],"_");
    strcpy(TitleBarButtons[2],"");

    //These are the symbols for the input boxes
    strcpy(InputBoxSy,"");//The Login in Symbol for Input Box
   }

  ~MiniOS()//deconstrutor
   {
    delete WndMain.WndQual.WndCaption;
    delete WndMain.WndQual.WndName;
    delete TitleBarButtons[0];
    delete TitleBarButtons[1];
    delete TitleBarButtons[2];
    delete Emotion[0];
    delete Emotion[1];
    delete Emotion[2];
    delete Emotion[3];
    delete InputBoxSy;
    delete ButtonLabel[0];
    delete ButtonLabel[1];
    delete ButtonLabel[2];
    delete ButtonLabel[3];
    delete LogFileName;
    closegraph();
   }

  WndMain WndMain;//Will Hold all information for the window
};
//*********************************************************************
//End MiniOS Class
//*********************************************************************

MiniOS OS;//Make a instance of the class global


void Screen_Back_Buffer();//This function will update the screen when need

//*********************************************************************
//Begin the main program point
//*********************************************************************
int main()
{
  //intailize graphics
  int graphdriver = DETECT, graphmode, errorcode;


  //Put the user into graphic mode
  initgraph(&graphdriver,&graphmode,"..\\BGI\\");
  errorcode = graphresult();//Use this to hold the number error

if (errorcode != grOk)  /* an error
			   occurred */
{
   cout<<"Error Number: "<<grapherrormsg(errorcode)<<endl;
   cout<<"There was a error detecting the hardware for you graphics"<<endl;
   cout<<"Try reinstalling the hardware or driver then try again"<<endl;
   cin.get();
   exit(1); /* terminate with an error code */
}


 //Veiw Logo
 settextstyle(DEFAULT_FONT,HORIZ_DIR,5);
 setcolor(GREEN);
 outtextxy(getmaxx()/2-180,getmaxy()/2-20,"GYNX 1.0");
 delay(3000);
 cleardevice();
 OS.Drawsprite("C:\\RGB.txt",(getmaxx()/2) - 50,(getmaxy()/2) - 50,74,91);
 setfillstyle(SOLID_FILL,BLACK);
 //Cover up te remains of him
 bar((getmaxx()/2) - 50,(getmaxy()/2) + 23,
			(getmaxx()/2) + 50,(getmaxy()/2) + 50);

 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
 setcolor(WHITE);

 //Display the qoute
 outtextxy((getmaxx()/2) - 180,(getmaxy()/2) + 50,
 "The secret to creativity is knowing how to hide");

 outtextxy((getmaxx()/2) - 180,(getmaxy()/2) + 65,
 "your sources. --Albert Einstein");
 cin.get();
 cleardevice();




 //intailize mouse compenents and other parts of miniOS
  outtextxy(1,1,"Enabling the graphics driver...");

  outtextxy(1,20,"Enabling the mouse driver...");
  OS.Mouse_Enable();
  outtextxy(1,40,"Reading the mouse driver...");
  OS.Mouse_Read_Cursor();
  outtextxy(1,60,"View the mouse...");
  OS.ShowMouse();
  //end mouse stuff
  outtextxy(1,80,"Setting defaults...");
  OS.Set_Default();
  outtextxy(1,100,"Creating Log File...");
  OS.Create_Log_File();


 cin.get();
 cleardevice();
 //*****************************************************************
 //End of the information to the user
 //*****************************************************************

 Screen_Back_Buffer();//All activity will take place in the back buffer




return 0;
}
//*****************************end main****************************
//
void Screen_Back_Buffer()
{
 int Button = 0;
 int Mouse_x = 0, Mouse_y = 0;

OS.Hide_Cursor();
OS.Create_Entire_Interface();//Create the interface for the project
OS.ShowMouse();
 //Create the interface for the window

 /*OS.CreateWindow(0,0,200,200,0,2,3,6,1);
 OS.Set_WndNumber();
 OS.CreateFolder(80,50,12);

 OS.CreateWindow(200,0,400,400,1,2,3,6,1);
 OS.Set_WndNumber();
 //Message Boxes
 OS.CreateMsgBox(0,0);
 OS.Set_WndNumber();
 OS.CreateMsgBox(0,1);
 OS.Set_WndNumber();
 OS.CreateMsgBox(0,2);
 OS.Set_WndNumber();
 */


 //Login Box
 OS.Hide_Cursor();
 OS.CreateMsgBox(1,4,"","","","","");
 OS.ShowMouse();
 OS.Set_WndNumber();


 OS.Mouse_Read_Cursor();

 cin.get();


   OS.CreateWindow(1,1,639,380,1,2,3,6,1);
    for (int I = 180; I < 380; I+=50)
     OS.CreateFolder(I,150,2);
     cin.get();

 //Create window ends
 outtext("HOLD UP");
 //A Ruff Start To Drag and Drop work when you return
 while(!kbhit())
  {
   OS.GetMousePos(&Button,&Mouse_x,&Mouse_y);

    if( Mouse_y <= getmaxx() && Mouse_x <= getmaxy() && Button == 1 )
      {


       OS.Hide_Cursor();
       OS.CreateWindow(Mouse_x,Mouse_y,Mouse_x + 100,Mouse_y + 100,1,2,3,6,1);

       OS.ShowMouse();
      }
  }


}//end update function


void MiniOS::Get_Wnd_Visual()
{
    int I = 0;

   for(I = 0; I < WndCount; I++)
    {
     //CReate the window
     CreateWindow(BkBuff[WndCount].WndSize,BkBuff[WndCount].WndX1,
		  BkBuff[WndCount].WndY1,BkBuff[WndCount].WndX2,
		  BkBuff[WndCount].WndY2,BkBuff[WndCount].WndStyle,
		  BkBuff[WndCount].WndFcColor,BkBuff[WndCount].WndLFcColor,
		  BkBuff[WndCount].WndBackGrd);
    }
}
void MiniOS::Set_WndNumber()
 {
  WndCount++;//Add one so the window will be able to have a back buffer
}
//*********************************************************************
//Very important function, this will show the windows on the screen
//There are three differant types 0-2
//*********************************************************************
int MiniOS::CreateWindow(int WndX1,int WndY1,int WndX2,int WndY2,
		   int WndStyle, int WndFcColor, int WndLFcColor,
		   int WndBackGrd, int WndTitleLine)
{

   settextstyle(DEFAULT_FONT,HORIZ_DIR,1);

   palettetype pal;//Contains palette information for the current graphics driver
   getpalette(&pal);//GetPalette demands that a pointer be passed

   WndMain.WndAttr.WndSize = sizeof(WndMain);
   WndMain.WndAttr.WndX1 = WndX1;
   WndMain.WndAttr.WndY1 = WndY1;
   WndMain.WndAttr.WndX2 = WndX2;
   WndMain.WndAttr.WndY2 = WndY2;
   WndMain.WndAttr.WndStyle = WndStyle;
   WndMain.WndAttr.WndFcColor =  WndFcColor;
   WndMain.WndAttr.WndLFcColor = WndLFcColor;
   WndMain.WndAttr.WndBackGrd = WndBackGrd;
   WndMain.WndAttr.WndTitleLine = WndTitleLine;

   //**************************************************************
       BkBuff[WndCount].WndSize = WndMain.WndAttr.WndSize;
       BkBuff[WndCount].WndX1 = WndMain.WndAttr.WndX1;
       BkBuff[WndCount].WndY1 = WndMain.WndAttr.WndY1;
       BkBuff[WndCount].WndX2 = WndMain.WndAttr.WndX2;
       BkBuff[WndCount].WndY2 = WndMain.WndAttr.WndY2;
       BkBuff[WndCount].WndStyle  = WndMain.WndAttr.WndStyle;
       BkBuff[WndCount].WndFcColor = WndMain.WndAttr.WndFcColor;
       BkBuff[WndCount].WndLFcColor = WndMain.WndAttr.WndLFcColor;
       BkBuff[WndCount].WndBackGrd = WndMain.WndAttr.WndBackGrd;
   //Create the BackBuffer Data
   //**************************************************************

 setfillstyle(SOLID_FILL,WndMain.WndAttr.WndBackGrd);
 bar(WndMain.WndAttr.WndX1+70, WndMain.WndAttr.WndY1+30,
      WndMain.WndAttr.WndX2,WndMain.WndAttr.WndY2);

 //Used to create the gradient titlebar
 for (int I=0; I<pal.size; I++)
  setrgbpalette(pal.colors[I], I*0, I*4, I*0);

  for (I=0; I<pal.size; I++)
   {
   setlinestyle(0,1,3);
   setfillstyle(SOLID_FILL,I);//Use the custom Color
   bar(WndMain.WndAttr.WndX1+I-1,WndMain.WndAttr.WndY1,WndMain.WndAttr.WndX2,
      WndMain.WndAttr.WndY1+30);
   }

//Info for grardient
 for (I=0; I<pal.size; I++)
 {
  setlinestyle(0,1,3);
  setfillstyle(SOLID_FILL,I);//Use the custom Color

  bar(WndMain.WndAttr.WndX1+I-1,WndMain.WndAttr.WndY1+30,
      WndMain.WndAttr.WndX1+70,
      WndMain.WndAttr.WndY2);
  }

 //Outer-most Border
 setlinestyle(0,1,3);
 setrgbpalette(pal.colors[WndMain.WndAttr.WndFcColor],0,63,45);//Custom Color
 setcolor(WndMain.WndAttr.WndFcColor);
 rectangle(WndMain.WndAttr.WndX1-2,WndMain.WndAttr.WndY1,WndMain.WndAttr.WndX2+2,
	   WndMain.WndAttr.WndY2);


 setlinestyle(0,1,2);

 //Gradient effect for outer most border
 setrgbpalette(pal.colors[WndMain.WndAttr.WndTitleLine + 1],0,25,0);//Custom Color
 setcolor(WndMain.WndAttr.WndTitleLine + 1);//Use the custom Color
 rectangle(WndMain.WndAttr.WndX1-2,WndMain.WndAttr.WndY1-2,WndMain.WndAttr.WndX2+2,
	   WndMain.WndAttr.WndY2+2);

 //Title Bar
 setlinestyle(0,1,3);
 setrgbpalette(pal.colors[WndMain.WndAttr.WndTitleLine],0,25,0);//Custom Color
 setcolor(WndMain.WndAttr.WndTitleLine);
 rectangle(WndMain.WndAttr.WndX1-2,WndMain.WndAttr.WndY1-2,WndMain.WndAttr.WndX2+2,
	   WndMain.WndAttr.WndY1+30);

 //Flashy Look for Title Bar
 setcolor(2);
 for(I = 5; I < 25; I+=5)
  {
   line(WndMain.WndAttr.WndX1+5,WndMain.WndAttr.WndY1+I,
	WndMain.WndAttr.WndX2-5,WndMain.WndAttr.WndY1+I);
  }

 //*******************for windows text*******************
 /*Caption for the newly created window
 //strcpy(WndMain.WndQual.WndName,"Test123Joshua");
 //strcpy(WndMain.WndQual.WndCaption,"Test123Joshua");
 //setcolor(BLACK);
 outtextxy(WndMain.WndAttr.WndX1+10,WndMain.WndAttr.WndY1+21,WndMain.WndQual.WndCaption);
 */

   //Create the close button caption this will equal WNDSTYLE - 0
    switch (WndMain.WndAttr.WndStyle)
     {
      case 0:
       //Create The Close button
	setcolor(20);
	setfillstyle(SOLID_FILL,20);
	setlinestyle(0,1,1);
	fillellipse(WndMain.WndAttr.WndX2 - 15, WndMain.WndAttr.WndY1 + 13,I/3,I/3);
	setcolor(45);
	outtextxy(WndMain.WndAttr.WndX2 - 18, WndMain.WndAttr.WndY1 + 10,TitleBarButtons[0]);
	//end WndStyle - 0
	break;
      case 1:
       //Create The Close button
	setcolor(20);
	setfillstyle(SOLID_FILL,20);
	setlinestyle(0,1,1);
	fillellipse(WndMain.WndAttr.WndX2 - 15, WndMain.WndAttr.WndY1 + 13,I/3,I/3);
	fillellipse(WndMain.WndAttr.WndX2 - 35, WndMain.WndAttr.WndY1 + 13,I/3,I/3);
	fillellipse(WndMain.WndAttr.WndX2 - 55, WndMain.WndAttr.WndY1 + 13,I/3,I/3);
	setcolor(45);

	outtextxy(WndMain.WndAttr.WndX2 - 18, WndMain.WndAttr.WndY1 + 10,TitleBarButtons[0]);
	outtextxy(WndMain.WndAttr.WndX2 - 39, WndMain.WndAttr.WndY1 + 10,TitleBarButtons[2]);
	outtextxy(WndMain.WndAttr.WndX2 - 58, WndMain.WndAttr.WndY1 + 10,TitleBarButtons[1]);
	break;
	//end WndStyle - 0
      case 2:
      break;
     }//end switch


  return(WndX1, WndY1, WndX2, WndY2, WndStyle, WndFcColor, WndLFcColor,
	WndBackGrd);

}
//*******************************************************************
//CreateTxtBox Function creates a textbox + label according to the
//coordinates.
//*******************************************************************

void MiniOS::CreateTxtBox_Lbl(int X1, int Y1, int X2, int Y2,char* TxtLabel)
{
     outtextxy(X1,Y1+10,TxtLabel);
     rectangle(X1+50,Y1,X2,Y2);
}



//*******************************************************************
//CreateFolder Function creates a folder according to the coordinates
//*******************************************************************
int MiniOS::CreateFolder(int X, int Y, int Color)
 {
  WndMain.WndFol.X = X;
  WndMain.WndFol.Y = Y;
  WndMain.WndFol.Color = Color;

  setfillstyle(SOLID_FILL,8);
  //Base of the folder and surroundings
  bar(WndMain.WndFol.X,WndMain.WndFol.Y,WndMain.WndFol.X + 30,
  WndMain.WndFol.Y + 20);

  //Top part of folder
  bar(WndMain.WndFol.X + 5,WndMain.WndFol.Y - 5,WndMain.WndFol.X  + 15,WndMain.WndFol.Y + 20);

 return(WndMain.WndFol.X,WndMain.WndFol.Y,WndMain.WndFol.Color);
}
//********************************************************
//Create_Log_File Creates the log file for the shell
//********************************************************
void MiniOS::Create_Log_File()
{
 //Create the log file for Shell
}
//********************************************************
//Set_Default Sets everything back to Zero or Defaults
//********************************************************
void MiniOS::Set_Default()
 {
   WndMain.WndAttr.WndSize = sizeof(WndMain);
   WndMain.WndAttr.WndX1 = 0;
   WndMain.WndAttr.WndY1 = 0;
   WndMain.WndAttr.WndX2 = 0;
   WndMain.WndAttr.WndY2 = 0;
   WndMain.WndAttr.WndStyle = 0;
   WndMain.WndAttr.WndFcColor =  0;
   WndMain.WndAttr.WndLFcColor = 0;
   WndMain.WndAttr.WndBackGrd = 0;
   WndMain.WndAttr.WndTitleLine = 0;
}
void MiniOS::Mouse_Enable()
{
 _AX=0;
 geninterrupt(0x33);
}

void MiniOS::Hide_Cursor()
{
 _AX=2;
 geninterrupt(0x33);

}

void MiniOS::Mouse_Read_Cursor()
{

      i.x.ax=1;
      int86(0x33,&i,&o);

      Mouse_x = _CX;
      Mouse_y = _DX;
    }
void MiniOS::GetMousePos(int *button,int *x, int *y)
{ // returns button clicked & position (x,y) on screen
  _AX=3;
  geninterrupt(0x33);
  *button=_BX;
  *x=_CX;
  *y=_DX;
}
void MiniOS::ShowMouse()
     {
       _AX=1;
       geninterrupt(0x33);
     }
void MiniOS::Create_Entire_Interface()
{
 palettetype pal;//Contains palette information for the current graphics driver
 getpalette(&pal);//GetPalette demands that a pointer be passed
 for(int I = 0; I < pal.size; I++)
    setrgbpalette(pal.colors[I],I * 4, I * 4, I * 4);


 setcolor(GREEN);


 //Draw the border
 rectangle(0,0,getmaxx(),getmaxy());
  for(int K = 10; K < getmaxx() - 10; K+=3)
  for(int L = 10; L < getmaxy() - 70; L+=2)
    putpixel(K,L,GREEN);

     setcolor(8);
     setlinestyle(0,1,3);

     rectangle(10,getmaxy()-10,getmaxx()-10, 420);
     setcolor(8);

}


//This function will create a message box
void MiniOS::CreateMsgBox(int MsgStyle,int ChoiceEm, char* Line1, char* Line2,
			  char* Line3, char* Line4, char* Line5)
{
 int MaxX = getmaxx()/2;
 int MaxY = getmaxy()/2;
 settextstyle(DEFAULT_FONT,HORIZ_DIR,1);

 if( (!Emotion[0]) || (!Emotion[1]) || (!Emotion[2])  || (!Emotion[3]) ||
     (!Emotion[4]) )
    {
     CreateMsgBox(0,ChoiceEm,"","","","","");//Recurssion thank God for it
     setcolor(BLACK);
     outtextxy(MaxX/2+90,MaxY/2+36,"Error allocating memory");
     cin.get();
    }

 //Create the actully message box window. It is no more then a window
    CreateWindow(MaxX/2+15,MaxY/2-10,MaxX/2+300,MaxY/2+150,2,2,3,6,1);
    settextstyle(DEFAULT_FONT,HORIZ_DIR,4);

    //Create the actuall point of the message box
    setfillstyle(SOLID_FILL,3);
    setcolor(3);
    fillellipse(MaxX/2+57,MaxY/2+50,25,25);

    //***********************************************
  //Create the buttons and message to the user
  //***********************************************
  //Button for form (OK)
     setcolor(32);
     setfillstyle(SOLID_FILL,16);
     rectangle(MaxX/2+90,MaxY/2+120,(MaxX/2+100) + 45,(MaxY/2+100) + 40);
     rectangle(MaxX/2+180,MaxY/2+120,(MaxX/2+100) + 140,(MaxY/2+100) + 40);

     //Button for Cancel();
     setcolor(32);
     setfillstyle(SOLID_FILL,16);
     rectangle(MaxX/2+90,MaxY/2+120,(MaxX/2+100) + 45,(MaxY/2+100) + 40);
     setcolor(2);

 switch(MsgStyle)
  {//begin switch

   //This option will be made for question
   case 0:
   outtextxy(MaxX/2+40,MaxY/2+36,Emotion[ChoiceEm]);
   settextstyle(DEFAULT_FONT,HORIZ_DIR,1);
   //Message to the user the main point of a message box :)
   setcolor(40);
    outtextxy(MaxX/2+90,MaxY/2+44,Line1);
    outtextxy(MaxX/2+90,MaxY/2+52,Line2);
    outtextxy(MaxX/2+90,MaxY/2+60,Line3);
    outtextxy(MaxX/2+90,MaxY/2+68,Line4);
    outtextxy(MaxX/2+90,MaxY/2+76,Line5);


   if( (ChoiceEm == 1) || (ChoiceEm == 2) )
    {

     //Text for the button
     setcolor(40);
     outtextxy(MaxX/2+110,MaxY/2+127,"OK");
     outtextxy(MaxX/2+187,MaxY/2+127,"CANCEL");

    }

   //Question MSGBOX
   if( (ChoiceEm == 0) )
     {
       setcolor(40);
       //Text for YES
       outtextxy(MaxX/2+105,MaxY/2+127,"YES");
       //Text for NO
       outtextxy(MaxX/2+203,MaxY/2+127,"NO");
     }
    break;

    case 1:
     //This will create the prompt user box
     //Text for the button
     //Create the symbol for that
     settextstyle(DEFAULT_FONT,HORIZ_DIR,4);
     setcolor(2);
     outtextxy(MaxX/2+40,MaxY/2+36,InputBoxSy);
     settextstyle(DEFAULT_FONT,HORIZ_DIR,1);

     //outtextxy(MaxX/2+17,MaxY/2+10,"Login");
     //Label Buttons
     setcolor(40);
     outtextxy(MaxX/2+110,MaxY/2+127,"OK");
     outtextxy(MaxX/2+187,MaxY/2+127,"CANCEL");
     //Draw the TextBox
     setcolor(10);

     //Login Screen
     CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+60,MaxX/2+290,MaxY/2+80,"ID:");
     CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+90,MaxX/2+290,MaxY/2+110,"CODE:");





     TypeEngine(MaxX/2+95,MaxY/2+75,10, 6,MaxX/2+260,
		MaxY/2+75,(MaxX/2+95)+55,(MaxY/2+75)+30,60);


   break;


    default:
    break;
  }//end switch


     cin.get();
}

//**************************************************************************
//This function will control all typing in the SHELL
//**************************************************************************
int MiniOS::TypeEngine(int XCor,int YCor,int Visible_Color, int Cover_Color,
		       int XBound, int YBound, int BackSpace_Bound,
		       int Tab_Bound, int Return_TabCoor)
{
  UserInfo UI;
  UI.ID = new char [15];
  UI.CODE = new char [15];

 int X = XCor+45, Y = YCor-8;//Used to hold the place for the cursor coordiantes
 //int MaxX = getmaxx() / 2, MaxY = getmaxy() / 2;
 char *Key = NULL;//The big string being used
 Key = 0;
 int I = -1, J = -1;//Give them the lowest value of the array

 //Allocation error
 if( (!UI.ID) || (!UI.CODE) )
    return -1;



  setcolor(Visible_Color);//Used to control color of cursor
  outtextxy(X+8,Y,"_");

  do
   {

    *Key = getch();

    setcolor(Visible_Color);//Used to control color of cursor
    outtextxy(X+16,Y,"_");
     //Control the Range
     X+=8;//Goto the next blank

    //Where main output happens
    if((*Key != 13) && (*Key != 8) && (*Key!= 9))
     {
      if(X <= (XBound))//X Boundries MaxX/2+260
       {
	  outtextxy(X,Y,Key);
	  setcolor(Cover_Color);
	  outtextxy(X,Y,"_");

	  //Control which string we are on for the login
	  if(Y <= (YBound))//Y Boundries MaxY/2+75
	   {
	    I+=1;
	    UI.ID[I] = (char)*Key;
	   }
	  else
	   {
	    J+=1;
	    UI.CODE[J] = (char)*Key;
	   }
       }
    else
       {
	X-=8;
	setcolor(Cover_Color);
	outtextxy(X,Y,"__");
	outtextxy(X,Y,"");
       }//end else
     }//end if

     if(*Key == 8)//Backspace
      {

       if(X >= BackSpace_Bound)//BackSpace Boundry XCor + 55
	{
	 //Preform BackSpace using a block to cover it up
	 X-=8;
	 setfillstyle(SOLID_FILL,Cover_Color);
	 bar(X,Y,X+8,Y+8);

	 //SetCursor to right place and cover its tracks
	 setcolor(Cover_Color);
	 outtextxy(X+8,Y,"__");
	 setcolor(Visible_Color);
	 outtextxy(X,Y,"_");

	 X-=8;
	 outtextxy(X,Y,"");

	  //Control which string we are on for the login
	  if(Y >= (YBound))//Max
	    {
	     I-=1;
	     UI.ID[I] = (char)" ";
	    }
	  else
	    {
	     J-=1;
	     UI.CODE[J]  = (char)" ";
	    }
	}//End if Outer IF

	//If the back space does exceeds its
	else
	 {
	  X-=0;
	  if(Y >= (YBound))//Max
	    {
	     I-=1;
	     UI.ID[I] = (char)" ";
	    }
	  else
	    {
	     J-=1;
	     UI.CODE[J] = (char)" ";
	    }

	  //Cover Procedure
	  setcolor(Cover_Color);
	  outtextxy(X+8,Y,"__");
	  setcolor(Visible_Color);
	  outtextxy(X,Y,"_");
	 }

      }//end if

     //This will be used as the tab key
     if(*Key == 9)
      {


       if(Y <= Tab_Bound)//YCor + 30 Tab Boundry
	{
	 setcolor(Cover_Color);
	 outtextxy(X,Y,"__");

	 Y+=30;
	 X=XCor+45;

	 //View the curosr
	 setcolor(Visible_Color);//Used to control color of cursor
	 outtextxy(X+8,Y,"_");

	}

       if( Y >= (Tab_Bound))//Move back up to ID
	{
	 setcolor(Cover_Color);
	 outtextxy(X,Y,"__");


	 Y-=Return_TabCoor;//60 was this Tab Return Boundry
	 X=XCor+45;

	 //View the curosr
	 setcolor(Visible_Color);//Used to control color of cursor
	 outtextxy(X+8,Y,"_");

	}
      }

      //Terminate the string so the computer will no where the end is
      UI.ID[I+1] = 0;
      UI.CODE[J+1] = 0;
     }while(*Key != 13);//end while loop

    //Cover Procedure
      setcolor(Cover_Color);
      outtextxy(X+8,Y,"__");


  //Lets check to see if the user wants a new account
  if(strcmpi(UI.ID,"NEW") == 0)
     User_Wizard();

  else if(strcmpi(UI.ID,"NEW") < 0)
    {
     //Display Cuurent Time and Date
     cleardevice();
     Create_Entire_Interface();
     CreateMsgBox(0,2,"Current Date\Time is:",Date,"Welcome to Gynx",UI.ID,"AAAAAAAAAAAAAAAAAAAAAAAA");
    }
   return 0;
}

void MiniOS::User_Wizard()
{
  int MaxX = getmaxx() / 2, MaxY = getmaxy() / 2;
  cleardevice();
    //OK Create Interface again
    Create_Entire_Interface();
    OS.CreateMsgBox(0,2,"You have entered new in","the box, this option will",
		    "allow you create a new","user. The wizard will","guide you.");

    cin.get();
    CreateWindow(170,100,490,300,0,2,3,6,1);

    //Window Caption
    setcolor(0);
    outtextxy(180,120,"New User Wizard ");

    //Draw the TextBox
     setcolor(10);

    setlinestyle(0,1,3);
    CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+20,MaxX/2+290,MaxY/2+40,"Id:");
    CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+50,MaxX/2+290,MaxY/2+70,"Code:");

    CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+80,MaxX/2+290,MaxY/2+100,"First:");
    CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+110,MaxX/2+290,MaxY/2+130,"Last:");
    CreateTxtBox_Lbl(MaxX/2+90,MaxY/2+140,MaxX/2+290,MaxY/2+160,"Sex:");

    TypeEngine(MaxX/2+95,MaxY/2+35,10, 6,MaxX/2+260,
	       MaxY/2+290,(MaxX/2+95)+55,(MaxY/2+160),150);

}
void MiniOS::Drawsprite(char SpriteFile[12],int XCo, int YCo, int StartX,
			int StartY)
{
 ifstream IFile;//this is the sprite file
 int X=0,Y=0;
 int Sprite[100][90];
 IFile.open(SpriteFile);
	for(X=0;X<StartX;X++)
	for(Y=0;Y<StartY;Y++)
		 IFile >> Sprite[Y][X];

	for(X=0;X<StartX;X++)
	for(Y=0;Y<StartY;Y++)
	  if(Sprite[X][Y] != 0)
	   putpixel(XCo+X,YCo+Y,Sprite[X][Y]);
	  else
	   putpixel(XCo+X,YCo+Y,0);
}